import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Textarea',
    fieldName: 'url',
    label: '文件访问地址',
  },
  {
    component: 'Input',
    fieldName: 'size',
    label: '文件大小，单位字节',
  },
  {
    component: 'Input',
    fieldName: 'filename',
    label: '文件名称',
  },
  {
    component: 'Input',
    fieldName: 'originalFilename',
    label: '原始文件名',
  },
  {
    component: 'Input',
    fieldName: 'basePath',
    label: '基础存储路径',
  },
  {
    component: 'Input',
    fieldName: 'path',
    label: '存储路径',
  },
  {
    component: 'Input',
    fieldName: 'ext',
    label: '文件扩展名',
  },
  {
    component: 'Input',
    fieldName: 'userId',
    label: '文件所属用户',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.FILE_TYPE 便于维护
      options: getDictOptions('file_type'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'fileType',
    label: '文件类型',
  },
  {
    component: 'Textarea',
    fieldName: 'attr',
    label: '附加属性',
  },
  {
    component: 'Input',
    fieldName: 'updateIp',
    label: '更新IP',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '文件id',
    field: 'id',
  },
  {
    title: '文件访问地址',
    field: 'url',
  },
  {
    title: '文件大小，单位字节',
    field: 'size',
  },
  {
    title: '文件名称',
    field: 'filename',
  },
  {
    title: '原始文件名',
    field: 'originalFilename',
  },
  {
    title: '基础存储路径',
    field: 'basePath',
  },
  {
    title: '存储路径',
    field: 'path',
  },
  {
    title: '文件扩展名',
    field: 'ext',
  },
  {
    title: '文件所属用户',
    field: 'userId',
  },
  {
    title: '文件类型',
    field: 'fileType',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.FILE_TYPE 便于维护
        return renderDict(row.fileType, 'file_type');
      },
    },
  },
  {
    title: '附加属性',
    field: 'attr',
  },
  {
    title: '备注',
    field: 'remark',
  },
  {
    title: '更新IP',
    field: 'updateIp',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '文件id',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '文件访问地址',
    fieldName: 'url',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '文件大小，单位字节',
    fieldName: 'size',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '文件名称',
    fieldName: 'filename',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '原始文件名',
    fieldName: 'originalFilename',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '基础存储路径',
    fieldName: 'basePath',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '存储路径',
    fieldName: 'path',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '文件扩展名',
    fieldName: 'ext',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '文件所属用户',
    fieldName: 'userId',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '文件类型',
    fieldName: 'fileType',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.FILE_TYPE 便于维护
      options: getDictOptions('file_type'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '附加属性',
    fieldName: 'attr',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '更新IP',
    fieldName: 'updateIp',
    component: 'Input',
    rules: 'required',
  },
];
